package leetcode.ge100;

import leetcode.lt100.TreeNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Solution_107 {



    public static void main(String[] args) {
    }


    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List res = new ArrayList<List<Integer>>();
        levelOrderBottom(root, res, 0);
        Collections.reverse(res);
        return res;
    }

    private void levelOrderBottom(TreeNode root, List<List<Integer>> res, int deep) {
        if (root != null) {
            if (res.size() == deep)
                res.add(new ArrayList<>());
            res.get(deep).add(root.val);
            levelOrderBottom(root.left, res, deep + 1);
            levelOrderBottom(root.right, res, deep + 1);
        }
    }

}